ImageGear Java PDF > How to... > Merge PDF Documents |
To merge two PDF documents:
The following is an illustration of how to merge two PDF documents:
Copy Code | |
---|---|
import com.accusoft.imagegearpdf.*; class PdfDemo { private PDF pdf; private Document document1; private Document document2; // Merge two PDF documents. public void mergeDocuments() { try { // Get page count for both of PDF documents. long pageCount1 = this.document1.getPageCount(); long pageCount2 = this.document2.getPageCount(); // Append all pages of the second document to the first document. this.document1.insertPages(pageCount1, this.document2, 0, pageCount2); } catch (Throwable ex) { // Failed to merge PDF documents. System.err.println("Exception: " + ex.toString()); } } } |